import * as vite from "vite";
import { defineConfig as baseConfig, mergeConfig } from "vite";

import { ConfigEnv, UserConfig, UserConfigExport } from "./types";
import viteConfig from "./vite.config";

// redefine defineConfig
const defineConfig = (config: UserConfigExport = {}): UserConfigExport => {
  if (typeof config === "function") {
    return baseConfig((params: ConfigEnv) =>
      mergeConfig(viteConfig, config(params) as UserConfig)
    );
  }
  return mergeConfig(viteConfig, config as UserConfig);
};

export { defineConfig, mergeConfig, vite };